package com.sporadic.backstage.controller;

import com.sporadic.backstage.entity.UserRank;
import com.sporadic.backstage.service.UserRankService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
@CrossOrigin(origins = {"http://localhost:8080"}, methods = {RequestMethod.GET, RequestMethod.POST}, allowCredentials = "true")
@Controller
public class UserRankController {
    @Autowired
    private UserRankService userRankService;

    /**
     * 查询商家所有积分列表信息
     * @param merchantId
     * @return
     */
    @RequestMapping("/selUserRankAll")
    @ResponseBody
    public List<UserRank> selUserRankAll(Integer merchantId){
       return userRankService.selUserRankAll(merchantId);
    }

    /**
     * 删除商家的指定积分信息
     * @param rankId 积分编号
     * @param merchantId 商家编号
     * @return 受影响的行数 大于0表示删除成功，否则失败
     */
    @ResponseBody
    @RequestMapping("/delUserRank")
    public Integer delUserRank(Integer rankId,Integer merchantId){
        return userRankService.delUserRank(rankId, merchantId);
    }

    /**
     * 添加商家的积分信息
     * @param userRank 积分信息详情
     * @return 受影响的行数 大于0表示添加成功，否则失败
     */
    @ResponseBody
    @RequestMapping("addUserRank")
    public Integer addUserRank(UserRank userRank){
        return userRankService.addUserRank(userRank);
    }

    /**
     * 修改商家积分信息
     * @param userRank 积分信息详情
     * @return 受影响的行数 大于0修改成功，否则修改失败
     */
    @ResponseBody
    @RequestMapping("/upUserRank")
    public Integer upUserRank(UserRank userRank){
        return userRankService.upUserRank(userRank);
    }

}
